<template>
  <div class="app-container">
    <div class="mt20 mb20 ml10 font-size-20">{{ allName }} 高龄库存</div>
    <el-table
    v-loading="loading"
    :data="highAgeWarehouseList"
    >
    <af-table-column prop="spckmc" label="仓库"></af-table-column>
    <af-table-column prop="spjs" label="结余件数"></af-table-column>
    <af-table-column prop="spsl" label="结余重量(吨)" ></af-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import { getListHighAgeWarehouse } from "@/api/storage/dataAnalysis/highAgeGoods";

export default {
  name: "HightAgeWarehouse",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //对齐
      labelPosition: "right",
      //加载列表
      loading: true ,
      //公司名
      allName:"",
      // 查询参数
      queryParams: {
        gaoling: "",
        khid: "",
      },
      // 按仓区分
      highAgeWarehouseList: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const query = to.query
    next(vm => {   
      if(Object.keys(query).length > 0) {
        vm.queryParams.khid = query.khid
        vm.queryParams.gaoling = query.gaoling
        vm.allName = query.allName
        vm.getList()
      }
    })
  },
  methods: {
    /** 查询按仓区分 */
    getList() {
      this.loading  = true
      getListHighAgeWarehouse(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.highAgeWarehouseList = response.rows;
        this.total = response.total;
        this.loading  = false
      });
    },

    //合计
    getSummaries({ columns, data }) {
      const sums = []
      columns.forEach((column, index) => {
        if(index === 0) {
          sums[index] = "合计"
			    return
        }
        if ((column.property === "spjs" || column.property === "spsl")) {
          const values = data.map((item) => {
            return parseFloat(this.delcommafy(item[column.property]))
          });
          sums[index] = values.reduce((prev, curr) => {
            return prev + curr
          }, 0);
        }
      })
      return sums
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
